package org.ztest.disruptor;

import java.nio.ByteBuffer;

import com.lmax.disruptor.RingBuffer;

/**
 * Event source
 * @author lhl
 *
 * 2015年11月5日 下午6:27:34
 */
public class LongEventProducer
{
	private final RingBuffer<LongEvent> ringBuffer;
	
	public LongEventProducer(RingBuffer<LongEvent> ringBuffer)
	{
		this.ringBuffer = ringBuffer;
	}
	
	// Produce message
	public void onData(ByteBuffer bb)
	{
		long sequence = ringBuffer.next();
		try
		{
			LongEvent event = ringBuffer.get(sequence);
			event.set(bb.getLong(0));
		}
		finally
		{
			ringBuffer.publish(sequence);
		}
	}
}
